import numpy as np
import cv2 as cv

# 创建16*16黑底照片
img = np.zeros((16, 16, 3), np.uint8)
cv.imshow("1_origin_img", img)

# 获取roi
# 定义ROI的坐标和尺寸
# x, y, w, h = 5, 5, 10, 10
# img[y:y+h,x:x+w]
roi_value = img[5:10, 5:10]  # 坐标[5,5], 长10, 宽10 的区域
print(roi_value)
""" 
[[[0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]
  [0 0 0]]
  ...
"""

# 修改roi
img[5:10, 5:10] = [0, 255, 0]  # 将 [5,5] 到 [10,10] 的像素值修改为 [0,255,0]

# 显示图片
cv.imshow("2_modify_roi_img", img)
cv.waitKey(0)
cv.destroyAllWindows()
